package routers

import (
	"beego/controllers"
	"beego/controllers/api"
	"github.com/astaxie/beego"
	// 引入Session
	"github.com/astaxie/beego/session"
	_ "github.com/astaxie/beego/session/mysql"
)

var globalSessions *session.Manager

func init() {
	// Session初始化(如果在正式项目里，需要单独将Session放到一个包内，全局初始化)
	sessionConfig := &session.ManagerConfig{
		CookieName:      "bee_sessId",
		EnableSetCookie: true,
		Gclifetime:      3600,
		Maxlifetime:     3600,
		Secure:          false,
		CookieLifeTime:  3600,
		ProviderConfig:  "./static/tmp",
	}
	globalSessions, _ = session.NewManager("memory", sessionConfig)
	go globalSessions.GC()

	// 404
	beego.ErrorController(&controllers.ErrorController{})

	// 自动路由
	beego.AutoRouter(&controllers.AboutController{})
	beego.AutoRouter(&controllers.ConvertController{})
	// http://121.4.62.116:8080/About/Custom

	// 固定路由
	beego.Router("/", &controllers.MainController{})
	beego.Router("/about", &controllers.AboutController{})
	beego.Router("/joinGet", &controllers.AboutController{}, "*:JoinGet")

	// 正则路由
	// beego.Router("/page/*",&controllers.AboutController{})
	beego.Router("/search", &controllers.AboutController{}, "*:Post")
	beego.Router("/detail/?:id([0-9]+).html", &controllers.AboutController{}, "*:Get")

	// 类型转换
	beego.Router("/convert/jtm", &controllers.ConvertController{}, "*:JsonToMap")
	beego.Router("/convert/baiduGet", &controllers.ConvertController{}, "*:BaiduNewsGet")

	// 学习
	beego.Router("/message/list/?:page([0-9]+).html", &api.MessageController{}, "*:ListGet")

	// ES
	beego.Router("/es/get", &controllers.EsearchController{})
	beego.Router("/es/search", &controllers.EsearchController{}, "*:Search")

	// Wechat
	beego.Router("/wechat/callback", &controllers.WechatController{}, "*:Callback")

	//API接口
	beego.Router("/api/api/tagsList", &api.ApiController{}, "*:TagsList")

	//代理OpenAI
	beego.Router("/api/gpt", &controllers.ProxyController{}, "*:Post")
}
